package animation6.view.zhaolixiang.com.viewanimation6

import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import android.view.animation.AccelerateInterpolator
import android.view.animation.BounceInterpolator

/**
 * Created by Administrator on 2017/12/24.
 */
class MyPointView: View {
    private var point:Point?=null
    constructor(context: Context):super(context)
    constructor(context:Context,atts:AttributeSet):super(context,atts)

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        if(point!=null){
            val paint= Paint()
            //抗锯齿
            paint.isAntiAlias=true
            paint.color= Color.RED
            paint.style=Paint.Style.FILL
            canvas.drawCircle(300f,300f,point!!.radius,paint)
        }
    }

    public fun doAnimation(start:Float,end:Float){
        val valueAnimator=ValueAnimator.ofObject(PointEvaluator(),Point(start)
        ,Point(end))
        valueAnimator.duration=5000
        valueAnimator.interpolator=BounceInterpolator()
        valueAnimator.addUpdateListener {
            animator->
            point=animator.animatedValue as Point
            invalidate()
        }
        valueAnimator.start()

    }
}